package com.jason.lightreader.controller;

import com.jason.lightreader.response.Result;
import com.jason.lightreader.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private ArticleService articleService;

    //获取我收藏的文章
    @GetMapping
    @PreAuthorize("isAuthenticated()")
    public Result getMyCollection() {
        return articleService.getMyCollection();
    }

    //判断文章是否收藏
    @GetMapping("/isCollect/{articleID}")
    @PreAuthorize("isAuthenticated()")
    public Result isCollected(@PathVariable Integer articleID) {
        return articleService.isCollected(articleID);
    }

    //根据id收藏一篇文章
    @GetMapping("/add/{articleID}")
    @PreAuthorize("isAuthenticated()")
    public Result addOrRemoveToMyCollection(@PathVariable Integer articleID) {
        return articleService.addOrRemoveToMyCollection(articleID);
    }
}
